package com.heiye.blog.ai.config;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: heiye
 * @date: 2025/11/07 下午7:11
 * @version: v1.0.0
 * @description: 配置异步任务执行器来消除只有 SimpleAsyncTaskExecutor 时带来的警告
 */
@Configuration
public class AsyncTaskExecutorConfig implements WebMvcConfigurer {

    @Resource(name = "httpRequestExecutor")
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
        // 设置异步任务执行器
        configurer.setTaskExecutor(threadPoolTaskExecutor);
        // 30秒超时
        configurer.setDefaultTimeout(30000L);
    }
}
